//
// RTSPSession.h
//
// $Id: //base/include/RTSPSession.h
//
// Library: base
// Package: RTSP
// Module : RTSPSession
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the RTSPSession class.
//
// Copyright (c) 2012-2012, iGuard.
//


#ifndef BASE_HTTPSession_INCLUDED
#define BASE_HTTPSession_INCLUDED

/**
	RTSPSession class ,a session mean more pair request and response,
	in fact,same as a connection between client and server,but this 
	session implement only logic code, not include any network transport
	code,aim to for high reuse code.
*/

#include "base.h"
#include "BaseHTTPRequest.h"
#include "BaseHTTPResponse.h"

#include <pjlib.h>
#include <string>

using namespace std;


class BASE_API BaseHTTPSession
{
public:
	BaseHTTPSession();
	virtual ~BaseHTTPSession();
	enum
	{
		HTTP_PORT = 80
	};
protected:
	int getCSeqID();
	void setCSeqID(int cseqID){m_cseqID = cseqID;};
public:
	int handleMessage0(const char* buff,int iLen,pj_size_t* iLeft);

protected:
	//clientsession and serversession must implement this method
//	virtual int handleMessage(RTSPMessage* pMessage)=0;
	virtual int handleMessage(BaseHTTPRequest& request)=0;
	virtual int handleMessage(BaseHTTPResponse& reply)=0;

protected:
	//client side,deal with reply from server
	  //virtual void OnReply(int status,BaseHTTPResponse& reply){};
	//virtual void OnOptionsReply(int status,RTSPResponse& reply){};
	//virtual void OnDescribeReply(int status,RTSPResponse& reply){};
	//virtual void OnSetupReply(int status,RTSPResponse& reply){};
	//virtual void OnPlayReply(int status,RTSPResponse& reply){};
	//virtual void OnPauseReply(int status,RTSPResponse& reply){};
	//virtual void OnRecordReply(int status,RTSPResponse& reply){};
	//virtual void OnTeardownReply(int status,RTSPResponse& reply){};
	//virtual void OnSetParameterReply(){};
	//virtual void OnGetParameterReply(){};
	//virtual void OnAnnounceReply(){};

	//server side,C->S
	//virtual void OnRedirectReply(){};
	//server side,deal with request from client
	//virtual void OnOptionsRequest(BaseHTTPRequest& request){};
	//virtual void OnGetRequest(BaseHTTPRequest& request){};
	//virtual void OnHeadRequest(BaseHTTPRequest& request){};
	//virtual void OnPostRequest(BaseHTTPRequest& request){};
	//virtual void OnPutRequest(BaseHTTPRequest& request){};
	//virtual void OnDeleteRequest(BaseHTTPRequest& request){};
	//virtual void OnTraceRequest(BaseHTTPRequest& request){};
	//virtual void OnConnectRequest(BaseHTTPRequest& request){};

public:
	//int makeOptionsRequest(std::string& req);
	//int makeSetParameterRequest(const std::string& req);
	//int makeGetParameterRequest(const std::string& req);
	//int makeAnnounceRequest(const std::string& req);

	//int makeOptionsReply(RTSPRequest& request,std::string& req);
	//int makeSetParameterReply(const std::string& req);
	//int makeGetParameterReply(const std::string& req);
	//int makeAnnounceReply(const std::string& req);
protected:
	void addCSeq(int seqid,string method);
	bool findCSeq(int seqid,string& method);
private:
	std::map<int,string> m_CSeqMap;
	std::map<int,string>::iterator m_CSeqIt;	

	int m_cseqID;
	//std::string m_sessionID;
	BaseHTTPRequest  m_Request;
	BaseHTTPResponse m_Reply;
};

#endif
